#ifndef LCD_H
#define LCD_H

#include "../Carama/carama.h"
#include "../Touch/input.h"
#include "../msg.h"
#include <pthread.h>
#include <time.h>

#define PIC_START_Y BUTTON_START_Y      // 图片开始显示的位置
#define PIC_WIDTH           200
#define PIC_HEIGHT          80

#define PIC1_START_X         0
#define PIC1_END_X          200        // 每个图片(也就是按钮的位置)

#define PIC2_START_X        200
#define PIC2_END_X          400

#define PIC3_START_X        400
#define PIC3_END_X          600

#define TEXT_START_X        600
#define TEST_START_Y        0           // 文本框显示的位置

#define CARAMA_MAX_X     CARAMA_MAX_WIDTH
#define CARAMA_MAX_Y     CARAMA_MAX_HEIGHT

#define PIC1_PATH "/mnt/button1.jpg"
#define PIC2_PATH "/mnt/button2.jpg"
#define PIC3_PATH "/mnt/button3.jpg"
#define LCD_PATH  "/dev/fb0"



struct lcd_info {
    int lcd_fd;
    int msg_fd;
    int width;
    int height;
    unsigned char  bpp;
    unsigned int current_text_row;  // 写到第几行了
    pthread_mutex_t lock;           // 对CacheBuffer的锁
    unsigned long screen_size;      // 屏幕需要的字节数(不是width * heigth 而是 width * height * bpp)
    unsigned char current_frame;    // 当前用的是哪一帧
    unsigned char* screen_base;     //显存的基地址
    unsigned char* CacheBuffer;     //缓存的地方

    struct itimerspec lcd_timer;     // 根据fps设定超时时间之类的动作 
    timer_t timerid;
};

struct jpeg_msg {
    unsigned char * buffer;     //存放图片的数据
    unsigned int width;         // 图片的高度
    unsigned int height;        // 图片的宽度
};

int lcd_init(const char * lcd_path);
void* lcd_thread(void * pvParameter);
void * convert_thread(void * pvParameter);
#endif